home *** CD-ROM | disk | FTP | other *** search
/ Super PC 34 / Super PC 34 (Shareware).iso / spc / UTIL / DJGPP2 / V2 / DJLSR200.ZIP / src / utils / echo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-13  |  916 b   |  51 lines

  1. /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  2. #include <stdio.h>
  3.  
  4. int
  5. main(int argc, char **argv)
  6. {
  7.   int i;
  8.   int nflag=0;
  9.   FILE *out = stdout;
  10.   while (argc > 1 && argv[1][0] == '-')
  11.   {
  12.     if ((argc > 2) && (strcmp(argv[1], "-o") == 0))
  13.     {
  14.       out = fopen(argv[2], "w");
  15.       if (!out)
  16.       {
  17.     perror(argv[2]);
  18.     out = stdout;
  19.       }
  20.       argc -= 2;
  21.       argv += 2;
  22.     }
  23.     if ((argc > 2) && (strcmp(argv[1], "-a") == 0))
  24.     {
  25.       out = fopen(argv[2], "a");
  26.       if (!out)
  27.       {
  28.     perror(argv[2]);
  29.     out = stdout;
  30.       }
  31.       argc -= 2;
  32.       argv += 2;
  33.     }
  34.     if ((argc > 1) && (strcmp(argv[1], "-n") == 0))
  35.     {
  36.       nflag = 1;
  37.       argc--;
  38.       argv++;
  39.     }
  40.   }
  41.   for (i=1; i<argc; i++)
  42.   {
  43.     if (i>1) fputc(' ', out);
  44.     fputs(argv[i], out);
  45.   }
  46.   if (!nflag)
  47.     fputc('\n', out);
  48.   fclose(out);
  49.   return 0;
  50. }
  51.